package org.dfl.plugin.editor.actions;

import org.dfl.messages.Messages;
import org.dfl.plugin.DflPlugin;
import org.dfl.plugin.editor.model.DflDiagram;
import org.eclipse.ui.IWorkbenchPart;


/**
 * make one step during flow running action (result tokens are disabled)
 * @author Piotr Wlodarczyk
 *
 */
public class ResumeOnceStepDisabledTokensAction extends org.eclipse.gef.ui.actions.SelectionAction {
	public static final String ACTION_ID = "ResumeOnceStepDisabledTokensAction"; //$NON-NLS-1$
	private DflDiagram diagram;

	public ResumeOnceStepDisabledTokensAction(IWorkbenchPart part, DflDiagram diagram) {
		super(part);
		this.diagram = diagram;
		setId(ACTION_ID);
		setImageDescriptor(DflPlugin.getImageDescriptor("icons/eclipse/rundebug2.gif")); //$NON-NLS-1$
		setHoverImageDescriptor(getImageDescriptor());
		setText(Messages.ResumeOnceStepDisabledTokensAction_0);
		setToolTipText(Messages.ResumeOnceStepDisabledTokensAction_1);
	}

	protected boolean calculateEnabled() {
		return (diagram!=null && diagram.isRunnning() && diagram.isPaused() && (diagram.isReadyToRun() || diagram.isRunningTransition()));
	}
	
	public void run() {
		diagram.resumeOnceStep(true);
	}
}
